package ee.serge.shared;

import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.gwt.user.client.rpc.IsSerializable;

@PersistenceCapable(detachable="true")
public class Loan implements IsSerializable {

   @PrimaryKey
   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
   private String key;
   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
   private Long ID;
   @Persistent
   private String name;
   @Persistent
   private String link;
   @Persistent
   private String comment;
   @Persistent
   private int minLoan;
   @Persistent
   private int maxLoan;
   @Persistent
   private int apr;
   @Persistent
   private int annualInterest;
   @Persistent
   private int transferFee;
   @Persistent
   private int period;
   @Persistent
   private boolean active;
   @Persistent
   private String imageLink;
   @Persistent
   private String screenshotLink;
   @Persistent
   private int feedbackCount;
   @Persistent
   private int totalRating;
   @Persistent
   private long creationTime = 0;
   
   /*
    * NotPersistent
    */
   @NotPersistent
   private int repay;
   @NotPersistent
   private java.util.List<Feedback> feedbackList;
   
   Loan() {}

   public Loan(String name, String link, String comment,
         int minLoan, int maxLoan, int apr, int annualInterest, int transferFee,
         int period, boolean active, String imageLink, String screenshotLink,
         int feedbackCount, int totalRating, List<Feedback> feedbackList) {
      this.name = name;
      this.link = link;
      this.comment = comment;
      this.minLoan = minLoan;
      this.maxLoan = maxLoan;
      this.apr = apr;
      this.annualInterest = annualInterest;
      this.transferFee = transferFee;
      this.period = period;
      this.active = active;
      this.imageLink = imageLink;
      this.screenshotLink = screenshotLink;
      this.feedbackCount = feedbackCount;
      this.totalRating = totalRating;
      this.feedbackList = feedbackList;
   }



   public String getKey() {
      return key;
   }

   public void setKey(String key) {
      this.key = key;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getLink() {
      return link;
   }

   public void setLink(String link) {
      this.link = link;
   }

   public String getImageLink() {
      return imageLink;
   }

   public void setImageLink(String imageLink) {
      this.imageLink = imageLink;
   }

   public String getComment() {
      return comment;
   }

   public void setComment(String comment) {
      this.comment = comment;
   }

   public int getMinLoan() {
      return minLoan;
   }

   public void setMinLoan(int minLoan) {
      this.minLoan = minLoan;
   }

   public int getMaxLoan() {
      return maxLoan;
   }

   public void setMaxLoan(int maxLoan) {
      this.maxLoan = maxLoan;
   }

   public int getAPR() {
      return apr;
   }

   public void setAPR(int apr) {
      this.apr = apr;
   }

   public int getPeriod() {
      return period;
   }

   public void setPeriod(int period) {
      this.period = period;
   }

   public boolean isActive() {
      return active;
   }

   public void setActive(boolean active) {
      this.active = active;
   }

   public String getScreenshotLink() {
      return screenshotLink;
   }

   public void setScreenshotLink(String screenshotLink) {
      this.screenshotLink = screenshotLink;
   }

   public int getFeedbackCount() {
      return feedbackCount;
   }

   public void setFeedbackCount(int feedbackCount) {
      this.feedbackCount = feedbackCount;
   }

   public int getTotalRating() {
      return totalRating;
   }

   public void setTotalRating(int totalRating) {
      this.totalRating = totalRating;
   }

   public java.util.List<Feedback> getFeedbackList() {
      return feedbackList;
   }

   public void setFeedbackList(java.util.List<Feedback> feedbackList) {
      this.feedbackList = feedbackList;
   }

   public Long getId() {
      return ID;
   }

   public void setId(Long id) {
      this.ID = id;
   }



   public long getCreationTime() {
      return creationTime;
   }
   
   public void increaseFeedbackCount() {
      feedbackCount++;
   }
   
   public void decreaseFeedbackCount() {
      feedbackCount--;
   }
   
   public void increaseTotalRating(int val) {
      totalRating += val;
   }



   public void setCreationTime(long creationTime) {
      this.creationTime = creationTime;
   }

   @Override
   public String toString() {
      return "Loan [key=" + key + ", id=" + ID + ", name=" + name + ", link="
            + link + ", comment=" + comment + ", minLoan=" + minLoan
            + ", maxLoan=" + maxLoan + ", annualInterest=" + apr
            + ", additionalFees=" + transferFee + ", period=" + period
            + ", active=" + active + ", imageLink=" + imageLink
            + ", screenshotLink=" + screenshotLink + ", feedbackCount="
            + feedbackCount + ", totalRating=" + totalRating
            + ", creationTime=" + creationTime + ", feedbackList="
            + feedbackList + "]";
   }

   public int getApr() {
      return apr;
   }

   public void setApr(int apr) {
      this.apr = apr;
   }

   public int getTransferFee() {
      return transferFee;
   }

   public void setTransferFee(int transferFee) {
      this.transferFee = transferFee;
   }

   public int getAnnualInterest() {
      return annualInterest;
   }

   public void setAnnualInterest(int annualInterest) {
      this.annualInterest = annualInterest;
   }

   public int getRepay() {
      return repay;
   }

   public void setRepay(int repay) {
      this.repay = repay;
   }
   
   
   
}
